package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiPurchaseIndexRecord;
import com.minimalist.common.entity.lindi.vo.purchaseindexrecord.LindiPurchaseIndexRecordQueryVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper;

/**
 * 林地指标平台_购买指标记录表 映射层。
 *
 * @author 11987
 * @since 2025-05-12
 */
public interface LindiPurchaseIndexRecordMapper extends BaseMapper<LindiPurchaseIndexRecord>{

    /**
     * 根据ID查询购买指标记录
     *
     * @param purchaseIndexRecordId 购买指标记录ID
     * @return 购买指标记录
     */
    default LindiPurchaseIndexRecord selectPurchaseIndexRecordByPurchaseIndexRecordId(Long purchaseIndexRecordId){
        return selectOneByQuery(QueryChain.create().eq(LindiPurchaseIndexRecord::getPurchaseIndexRecordId, purchaseIndexRecordId));
    }

    /**
     * 分页查询购买指标记录列表
     *
     * @param queryVO 查询条件
     * @return 分页结果
     */
    default Page<LindiPurchaseIndexRecord> selectPagePurchaseIndexRecordList(LindiPurchaseIndexRecordQueryVO queryVO){
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .like(LindiPurchaseIndexRecord::getPurchaseIndexRecordCode, queryVO.getPurchaseIndexRecordCode())
                        .ge(LindiPurchaseIndexRecord::getPurchaseTime, queryVO.getPurchaseTimeStart())
                        .le(LindiPurchaseIndexRecord::getPurchaseTime, queryVO.getPurchaseTimeEnd())
                        .orderBy(LindiPurchaseIndexRecord::getCreateTime, false));
    }
}
